package com.kuang.demo.controller;

import com.kuang.demo.bean.BaseRespVo;
import com.kuang.demo.bo.gh.QueryOrderListBO;
import com.kuang.demo.bo.gh.RefundOrderBO;
import com.kuang.demo.bo.gh.ShipOrderBO;
import com.kuang.demo.dto.BrandDTO;
import com.kuang.demo.service.OrderService;
import com.kuang.demo.vo.OrderDetailVO;
import com.kuang.demo.vo.OrderRefundVO;
import com.kuang.demo.vo.QueryOrderListVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * Created by 郭浩 on 2020/10/31 15:54
 */
@RestController
@RequestMapping("admin/order")
public class OrderController {
    @Autowired
    OrderService orderService;

    @GetMapping("list")
    public BaseRespVo orderList(QueryOrderListBO queryOrderListBO){
        QueryOrderListVO queryOrderListVO = new QueryOrderListVO();
        Map<String, Object> orderInfo = orderService.queryOrderList(queryOrderListBO);
        //查询总数
        int total = (int) orderInfo.get("total");
        List<QueryOrderListVO.ItemsBean>  orderList = (List<QueryOrderListVO.ItemsBean>) orderInfo.get("orderList");
        queryOrderListVO.setItems(orderList);
        queryOrderListVO.setTotal(total);
        return BaseRespVo.ok(queryOrderListVO);
    }

    //GET http://localhost:8083/admin/order/detail?id=1 HTTP/1.1
    @GetMapping("detail")
    public BaseRespVo orderDetail(Integer id){
        OrderDetailVO orderDetailVO = orderService.queryOrderDetail(id);

        return BaseRespVo.ok(orderDetailVO);
    }

    @PostMapping("ship")
    public BaseRespVo orderShip(@RequestBody ShipOrderBO shipOrderBO){
        orderService.shipOrder(shipOrderBO);
        return BaseRespVo.ok();
    }

    @PostMapping("refund")
    public BaseRespVo orderRefund(@RequestBody RefundOrderBO refundOrderBO){
        orderService.refundOrder(refundOrderBO);
//        return new OrderRefundVO(202,"订单退款成功");
        return BaseRespVo.ok();
    }

}
